using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VICC_ZLAN
    {

        public void SetUpNewRow(ref DataRow dwReturn)
        {
            #region
            #endregion
            switch (app.company)
            {
                case "YGR":
                case "SXN":
                case "TST":
                default:
                    #region====YGR======
                    dwReturn["MANDANT"] = "00";
                    dwReturn["ABAID"] = 0;
                    dwReturn["HDEV"] = 0;

                    dwReturn["DEVTYP"] = "FXPLC".PadRight(20);
                    dwReturn["MACHINEID"] = "".PadRight(20);
                    dwReturn["PDAID"] = "".PadRight(20);
                    dwReturn["WHLOCATION"] = "".PadRight(20);
                    dwReturn["ITEMID"] = "".PadRight(20);


                    dwReturn["DEVNAME"] = "".PadRight(10);
                    dwReturn["IPMODE"] = " ";
                    dwReturn["LOCALIP"] = "".PadRight(20);
                    dwReturn["NETMASK"] = "".PadRight(20);
                    dwReturn["GATEWAY"] = "".PadRight(20);
                    dwReturn["DNSSERVERIP"] = "".PadRight(20);
                    dwReturn["WORKMODE"] = 0;
                    dwReturn["LOCALPORT"] = 25003;
                    dwReturn["DESTMODE"] = 0;
                    dwReturn["SERVRENAME"] = "".PadRight(30);
                    dwReturn["SERVERIP"] = "".PadRight(20);
                    dwReturn["SERVERPORT"] = 25003;
                    dwReturn["BAUDRATEINDEX"] = 0;
                    dwReturn["PARITY"] = 0;
                    dwReturn["DATABITS"] = 0;
                    dwReturn["STOPBITS"] = 0;
                    dwReturn["FLOWCONTROL"] = 0;
                    dwReturn["MAXPACKETLEN"] = 0;
                    dwReturn["MAXTIMEGAP"] = 0;
                    dwReturn["APPPROTOCOL"] = 0;
                    dwReturn["RECONNECTTIME"] = 0;
                    dwReturn["KEEPALIVETIME"] = 0;
                    dwReturn["WEBPORT"] = 0;
                    dwReturn["STATUS"] = 0;
                    dwReturn["RESOURCEIP"] = "".PadRight(20);
                    dwReturn["RESOURCEPORT"] = 0;
                    dwReturn["VER"] = "".PadRight(20);
                    dwReturn["FUNCSEL"] = "".PadRight(20);
                    dwReturn["FUNCSEL2"] = "".PadRight(20);
                    dwReturn["UDPGROUPIP"] = "".PadRight(16);
                    dwReturn["DEVID"] = "".PadRight(20);
                    dwReturn["IO"] = " ";
                    dwReturn["FUNCEN"] = 0;
                    dwReturn["SERVERMODEPARAMT"] = 0;
                    dwReturn["ZP0"] = "".PadRight(20);
                    dwReturn["ZP1"] = "".PadRight(20);
                    dwReturn["ZP2"] = "".PadRight(20);
                    dwReturn["ZP3"] = "".PadRight(20);
                    dwReturn["ZP4"] = "".PadRight(20);
                    dwReturn["ZP5"] = "".PadRight(20);
                    dwReturn["ZP6"] = "".PadRight(20);
                    dwReturn["ZP7"] = "".PadRight(20);
                    dwReturn["ZP8"] = "".PadRight(20);
                    dwReturn["ZP9"] = "".PadRight(20);
                    dwReturn["ZP10"] = "".PadRight(200);
                    dwReturn["DATASEND"] = "".PadRight(200);
                    dwReturn["NEWUSER"] = "".PadRight(8);
                    dwReturn["NEWDATE"] = "".PadRight(8);
                    dwReturn["CHGUSER"] = "".PadRight(8);
                    dwReturn["CHGDATE"] = "".PadRight(8);
                    #endregion
                    break;

            }
        }
        public void InsertICC_ZLAN(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            dwData["NEWUSER"] = app.User;
            dwData["NEWDATE"] = date;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                default:
                case "YGR":
                    or1.CommandText = "INSERT INTO ICC_ZLAN ( MANDANT,ABAID,HDEV,DEVTYP,MACHINEID,PDAID,WHLOCATION,ITEMID,DEVNAME,IPMODE,LOCALIP,LOCALPORT,NETMASK,GATEWAY,DNSSERVERIP,WORKMODE,DESTMODE,SERVERIP,SERVRENAME,SERVERPORT,BAUDRATEINDEX,PARITY,DATABITS,STOPBITS,FLOWCONTROL,MAXPACKETLEN,MAXTIMEGAP,APPPROTOCOL,RECONNECTTIME,KEEPALIVETIME,WEBPORT,STATUS,RESOURCEIP,RESOURCEPORT,VER,FUNCSEL,FUNCSEL2,UDPGROUPIP,DEVID,IO,FUNCEN,SERVERMODEPARAMT,ZP0,ZP1,ZP2,ZP3,ZP4,ZP5,ZP6,ZP7,ZP8,ZP9,ZP10,DATASEND,NEWUSER,NEWDATE,CHGUSER,CHGDATE)"
                   + " VALUES (:MANDANT:,:ABAID:,:HDEV:,:DEVTYP:,:MACHINEID:,:PDAID:,:WHLOCATION:,:ITEMID:,:DEVNAME:,:IPMODE:,:LOCALIP:,:LOCALPORT:,:NETMASK:,:GATEWAY:,:DNSSERVERIP:,:WORKMODE:,:DESTMODE:,:SERVERIP:,:SERVRENAME:,:SERVERPORT:,:BAUDRATEINDEX:,:PARITY:,:DATABITS:,:STOPBITS:,:FLOWCONTROL:,:MAXPACKETLEN:,:MAXTIMEGAP:,:APPPROTOCOL:,:RECONNECTTIME:,:KEEPALIVETIME:,:WEBPORT:,:STATUS:,:RESOURCEIP:,:RESOURCEPORT:,:VER:,:FUNCSEL:,:FUNCSEL2:,:UDPGROUPIP:,:DEVID:,:IO:,:FUNCEN:,:SERVERMODEPARAMT:,:ZP0:,:ZP1:,:ZP2:,:ZP3:,:ZP4:,:ZP5:,:ZP6:,:ZP7:,:ZP8:,:ZP9:,:ZP10:,:DATASEND:,:NEWUSER:,:NEWDATE:,:CHGUSER:,:CHGDATE:)";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
            }
            Connect2Proxy(or1);
        }

        public DataSet QICC_ZLAN01(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT * FROM ICC_ZLAN "
                              + " WHERE MANDANT =:MANDANT: AND ABAID =:ABAID: ";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = "ICC_ZLAN";
            return SResult;
        }
        public DataSet QICC_ZLAN02(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT * FROM ICC_ZLAN "
                        + " WHERE MANDANT =:MANDANT: AND DEVID =:DEVID: ";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = "ICC_ZLAN";
            return SResult;
        }
        public DataSet QICC_ZLAN03(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT M.* FROM ICC_ZLAN M "
                      + " JOIN AMSTAMM ON AMMANDANT=MANDANT AND TRIM(AMHERST)=TRIM(LOCALIP)"
                        + " WHERE MANDANT =:MANDANT:   ";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = "ICC_ZLAN";
            return SResult;
        } 
       
        public DataSet QICC_ZLAN04(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT * FROM ICC_ZLAN "
                        + " WHERE MANDANT =:MANDANT: AND  TRIM(LOCALIP) =:LOCALIP: ";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = "ICC_ZLAN";
            return SResult;
        }
        public DataSet QICC_ZLAN05(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT E.*,M.*,AMEBDEKEN FROM ICC_ZLAN M JOIN AMSTAMM ON MANDANT=AMMANDANT AND TRIM(LOCALIP)=TRIM(AMHERST)"
                        + " JOIN AMEINST E ON  AMEMANDANT=AMMANDANT AND AMENRKRS=AMNRKRS AND AMELFDNR=AMLFDNR  AND AMEPOS=AMPOS"
                        + " WHERE MANDANT =:MANDANT: "
                        + dwData["LOCALIP"].ToString()
                        + " ORDER BY AMEMODNR,AMEEINSTNR";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = "ICC_ZLAN";
            return SResult;
        }

        public void DZLAN01(DataRow dwData)
        {

            or1 = OracleDB.CreateCommand();
            or1.CommandText = "DELETE FROM ICC_ZLAN  "
                + " WHERE MANDANT =:MANDANT: AND ABAID =:ABAID: ";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            Connect2Proxy(or1);
        }
        public void DZLAN02(DataRow dwData)
        {

            or1 = OracleDB.CreateCommand();
            or1.CommandText = "DELETE FROM ICC_ZLAN  "
                + " WHERE MANDANT =:MANDANT: AND LOCALIP =:LOCALIP: ";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            Connect2Proxy(or1);
        }
      

        public void UpdateICC_ZLAN(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            if (option == 0)
            {
                switch (app.company)
                {
                    default:
                        UZLAN01(dwData);
                        break;
                }
            } 
        }
        public void UZLAN01(DataRow dwData)
        {
            dwData["CHGUSER"] = app.User;
            dwData["CHGDATE"] = date;
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "UPDATE ICC_ZLAN SET MANDANT=:MANDANT:,ABAID=:ABAID:,HDEV=:HDEV:,DEVTYP=:DEVTYP:,MACHINEID=:MACHINEID:,PDAID=:PDAID:,WHLOCATION=:WHLOCATION:,ITEMID=:ITEMID:,DEVNAME=:DEVNAME:,IPMODE=:IPMODE:,LOCALIP=:LOCALIP:,LOCALPORT=:LOCALPORT:,NETMASK=:NETMASK:,GATEWAY=:GATEWAY:,DNSSERVERIP=:DNSSERVERIP:,WORKMODE=:WORKMODE:,DESTMODE=:DESTMODE:,SERVERIP=:SERVERIP:,SERVRENAME=:SERVRENAME:,SERVERPORT=:SERVERPORT:,BAUDRATEINDEX=:BAUDRATEINDEX:,PARITY=:PARITY:,DATABITS=:DATABITS:,STOPBITS=:STOPBITS:,FLOWCONTROL=:FLOWCONTROL:,MAXPACKETLEN=:MAXPACKETLEN:,MAXTIMEGAP=:MAXTIMEGAP:,APPPROTOCOL=:APPPROTOCOL:,RECONNECTTIME=:RECONNECTTIME:,KEEPALIVETIME=:KEEPALIVETIME:,WEBPORT=:WEBPORT:,STATUS=:STATUS:,RESOURCEIP=:RESOURCEIP:,RESOURCEPORT=:RESOURCEPORT:,VER=:VER:,FUNCSEL=:FUNCSEL:,FUNCSEL2=:FUNCSEL2:,UDPGROUPIP=:UDPGROUPIP:,DEVID=:DEVID:,IO=:IO:,FUNCEN=:FUNCEN:,SERVERMODEPARAMT=:SERVERMODEPARAMT:,ZP0=:ZP0:,ZP1=:ZP1:,ZP2=:ZP2:,ZP3=:ZP3:,ZP4=:ZP4:,ZP5=:ZP5:,ZP6=:ZP6:,ZP7=:ZP7:,ZP8=:ZP8:,ZP9=:ZP9:,ZP10=:ZP10:,DATASEND=:DATASEND:,NEWUSER=:NEWUSER:,NEWDATE=:NEWDATE:,CHGUSER=:CHGUSER:,CHGDATE=:CHGDATE:"
                                         + " WHERE MANDANT=:MANDANT: AND ABAID=:ABAID:";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            Connect2Proxy(or1);
        }
        public void UZLAN02(DataRow dwData)
        { 
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "UPDATE ICC_ZLAN SET  DEVTYP=:DEVTYP:"
                                         + " WHERE MANDANT=:MANDANT: AND LOCALIP=:LOCALIP:";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            Connect2Proxy(or1);
        }

    }
}
